how to open link in new tab in react js

127

how to open a new tab in react -

//More Secure Solution. For JS only.

const openInNewTab = (url) => {
  const newWindow = window.open(url, '_blank', 'noopener,noreferrer')
  if (newWindow) newWindow.opener = null
}

//Then add to your onClick
onClick={() => openInNewTab('https://stackoverflow.com')}

how to open link in new tab in react js -

<td onClick={()=> window.open("someLink", "_blank")}>text</td>

how to open link in new tab in react js -

import React from "react";

function App() {
  const handleClick = () => {
    window.open("http://twitter.com/saigowthamr");
  };

  return (
    <div>
      <h2>App</h2>
      <button onClick={handleClick}>Twitter</button>
    </div>
  );
}

export default App;

open in a new tab react -

<td onClick={()=> window.open("someLink", "_blank")}>text</td>

Comments

Submit
0 Comments